package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Product;
import service.impl.ProductManagerFactory;

/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet("/sec/goingupdate")
public class ProductItemServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductItemServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pid = request.getParameter("id");
		Product  p = ProductManagerFactory.getInstance().getProduct(pid);
		
		request.getSession().setAttribute("uuid", pid);
		System.out.println("session中设置的pid： "+pid);
		
		request.setAttribute("uid", p.getId());
		request.setAttribute("pname", p.getName());

		request.setAttribute("pprice", p.getPrice());
		request.setAttribute("pcount", p.getCount());
		request.setAttribute("pdate", p.getPd());
		request.setAttribute("curw", p.getWid());
		
		System.out.println("获取到 pdate： "+p.getPd());
		
		request.getRequestDispatcher("update.jsp").forward(request, response);
	}

}
